feat(browser): export aria tree utils#10171
feat(browser): export aria tree utils#10171hi-ogawa wants to merge 12 commits intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
@vitest/browser
@vitest/browser-playwright
@vitest/browser-preview
@vitest/browser-webdriverio
@vitest/coverage-istanbul
@vitest/coverage-v8
@vitest/expect
@vitest/mocker
@vitest/pretty-format
@vitest/runner
@vitest/snapshot
@vitest/spy
@vitest/ui
@vitest/utils
vitest
@vitest/web-worker
@vitest/ws-client
commit: |
| /** | ||
| * Utilities for generating and working with ARIA trees and templates. | ||
| * @experimental | ||
| */ | ||
| aria: { | ||
| /** Captures the ARIA tree for a DOM subtree. */ | ||
| generateAriaTree: typeof __ivyaAriaTypes.generateAriaTree | ||
| /** Renders a captured ARIA tree to the textual snapshot format. */ | ||
| renderAriaTree: typeof __ivyaAriaTypes.renderAriaTree | ||
| /** Renders an ARIA template back to text. */ | ||
| renderAriaTemplate: typeof __ivyaAriaTypes.renderAriaTemplate | ||
| /** Parses textual ARIA snapshot syntax into a template tree. */ | ||
| parseAriaTemplate: typeof __ivyaAriaTypes.parseAriaTemplate | ||
| /** Matches a captured ARIA tree against a parsed template. */ | ||
| matchAriaTree: typeof __ivyaAriaTypes.matchAriaTree | ||
| } |
There was a problem hiding this comment.
Typescript couldn't infer jsdoc from the original ivya/aria exports (likely due to dts bundling), so I wrote up it manually by partially duplicating the ones in ivya.
AriPerkkio
left a comment
There was a problem hiding this comment.
Looks good, this will allow users to use a11y tree utils without having to install another ivya next to the bundled one.
| get aria() { | ||
| return __INTERNAL._aria | ||
| }, |
There was a problem hiding this comment.
What exactly does this work-around fix? Why not import { aria } from "./aria" and return that here?
There was a problem hiding this comment.
There's some weird @vitest/browser client bundle split and we have tester/context.ts and tester/expect-element.ts independently built without sharing chunks. Previously ivya/aria lived only in expect-element bundle, but this one now needs to be available from context.ts, so it's passed through __INTERNAL global.
There's other globals that are passed around like __vitest_browser_runner__, but haven't fully understood what is for what.
|
This is pretty awesome! How does it compare to Playwright's Where the AI mode also captures iframe's contents and adds unique references to each element. |
Our implementation is stripped down port and AI part isn't included. https://github.com/vitest-dev/ivya/blob/7d84867d3576ac9c7342299e552d3c78a60a272b/src/aria/folk/injected/ariaSnapshot.ts#L17-L20 It's expected to exactly match with their |
Description
toMatchAriaInlineSnapshotcannot match empty aria trees #10158This PR exposes
ivya/ariaexports viaimport { utils } from "vitest/browser". This can be useful as a standalone primitive of "node to aria tree" serialization similar toprettyDOMdoes for "ndoe to html like" serialization.The wiring is a bit mess like
__INTERNALand@vitest/browser/internal/vendor-types, but seems necessary to avoid duplicating modules and also hand-rolling same type definition. For example, I noticedtype AriaRoleis currently manually written inpackages/browser/aria-role.d.tsbut this can also come fromivyawith similar tricks.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.